import {
  request
} from '../../request/index'
import regeneratorRuntime from '../../lib/runtime/runtime'
import moment from 'moment'

Page({

  data: {
    userInfo: {},
    createDays: "",
    createTime: "",
    month: "",
    day: "",
    playList: [],
    playCount: []

  },
  onLoad: function (options) {
    let {id} = options
    // let userInfo = wx.getStorageSync("userinfo");
    // let id = userInfo.userId

    this.getUserInfo(id)
    this.getUserSongList(id)
  },

  //获取用户信息
  async getUserInfo(id) {
    let {
      data
    } = await request({
      url: "/user/detail",
      data: {
        uid: id
      }
    })

    let {
      createDays
    } = data

    let month = moment(data.createTime).format('YYYY')
    let day = moment(data.createTime).format('MM')
    
    let birthday = moment(data.profile.birthday).format('YYYY')
    if (birthday > 1969 && birthday <= 1979) {
      var time = 70
    } else if (birthday > 1979 && birthday <= 1989) {
      var time = 80
    } else if (birthday > 1989 && birthday <= 1999) {
      var time = 90
    } else if (birthday > 1999 && birthday <= 2010) {
      var time = "00"
    } else if (birthday > 2010 && birthday <= 2019) {
      var time = 10
    } else if (birthday > 2019 && birthday <= 2029) {
      var time = 20
    }
    this.setData({
      userInfo: data,
      createDays: Math.floor((createDays * 1) / 365),
      month,
      day,
      birthday: time

    })

    wx.setNavigationBarTitle({
      title: data.profile.nickname,
    });

  },

  //获取用户歌单
  async getUserSongList(id) {
    let {
      data
    } = await request({
      url: "/user/playlist",
      data: {
        uid: id
      }
    })

    this.setData({
      playList: data.playlist,
    })



  }


})